package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: ShopController
 * Package: com.sky.controller.admin
 * Description:   店铺的营业状态存入Redis中
 *
 * @Autehor 屈子岩
 * @Create 2024/9/10 15:26
 * @Version 1.0
 */
@RequestMapping("user/shop")
@RestController("userShopController")
@Slf4j
@Api("店铺操作接口")
public class ShopController {


    public static final String key = "SHOP_STATUS" ;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 获取当前营业状态
     * @return
     */
    @GetMapping("status")
    public Result<Integer> getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get(key);
        log.info("店铺营业状态为:{}",status == 1 ? "营业中":"打烊中");
        return Result.success(status);
    }
}
